-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(web): display errors msg got from be #1343
Conversation
Warning Rate limit exceeded@soneda-yuya has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 34 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughThis pull request introduces a comprehensive overhaul of error handling mechanisms across multiple files in the web application. The primary change is transitioning from a single-error to a multi-error management approach. This involves modifying error-related functions, atoms, and hooks to support arrays of errors, adding more detailed error information, and updating error reporting and notification systems. A new Changes
Sequence DiagramsequenceDiagram
participant Client
participant GraphQLProvider
participant ErrorLink
participant Sentry
participant Notifications
Client->>GraphQLProvider: Make GraphQL Request
GraphQLProvider->>ErrorLink: Process Request
alt Network Error
ErrorLink-->>Sentry: Report Network Error
ErrorLink-->>Notifications: Create Error Notification
else GraphQL Errors
ErrorLink->>ErrorLink: Transform Errors
ErrorLink-->>Sentry: Report Multiple Errors
ErrorLink-->>Notifications: Create Error Notifications
end
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
51ba37d
to
eb619f0
Compare
eb619f0
to
0ae0aed
Compare
✅ Deploy Preview for reearth-web ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Nitpick comments (6)
web/src/services/gql/provider/links/langLink.ts (1)
5-13
: Add TypeScript types for better type safety.Consider adding explicit type definitions for the context and headers:
+ interface Headers { + [key: string]: string; + } + + interface Context { + headers?: Headers; + } - return setContext(async (_, { headers }) => { + return setContext(async (_, { headers }: Context) => {web/src/sentry.ts (1)
15-26
: Improve type checking in error handling.While the array-based error reporting looks good, the type checking could be enhanced:
- The
instanceof Error
check might not catch all error types sinceerror
is of typeReportError
- The type definition suggests
error
should havetype
andmessage
propertiesConsider this implementation:
export const reportError = (errors: ReportError[]) => { errors.forEach((error) => { - if (error instanceof Error) { + if (error instanceof Error || error.constructor?.name === 'Error') { Sentry.captureException(error); } else { Sentry.captureException( new Error( `${error.type || "Unknown"}: ${error.message || "No message provided"}` ) ); } }); };web/src/services/gql/provider/links/errorLink.ts (1)
14-16
: Improve null-safety in network error handling.The optional chaining on
networkError?.message
is redundant in the array initialization since it's already checked in the condition.if (networkError?.message) { errors = [ - { message: networkError?.message, description: networkError.message } + { message: networkError.message, description: networkError.message } ];web/src/beta/features/Notification/hooks.ts (3)
26-26
: Consider adding explicit type annotations for better type safety.While the code works, adding explicit type annotations would improve type safety and code documentation.
- const [errors, setErrors] = useErrors(); + const [errors, setErrors] = useErrors<Array<{ message?: string; description?: string }>>();
54-55
: Consider deduplicating error messages.When processing multiple errors, consider deduplicating similar messages to prevent notification spam.
- errors.forEach((error) => { + const uniqueErrors = errors.filter((error, index, self) => + index === self.findIndex(e => e.message === error.message) + ); + uniqueErrors.forEach((error) => {
70-82
: Consider prioritizing error notifications.The current implementation shows all errors sequentially. Consider prioritizing critical errors or grouping similar errors.
+ const errorPriority = error.message?.includes("policy violation") ? 1 : 2; + const notification = { + priority: errorPriority, type: error.message?.includes("policy violation") ? "info" : "error", heading: error.message?.includes("policy violation") ? noticeHeading : errorHeading, text: error.message?.includes("policy violation") ? message : (error.description || error.message || ""), ...(error.message?.includes("policy violation") && { duration: "persistent" }) + };
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
web/src/beta/features/Notification/hooks.ts
(3 hunks)web/src/sentry.ts
(1 hunks)web/src/services/gql/provider/index.tsx
(2 hunks)web/src/services/gql/provider/links/errorLink.ts
(1 hunks)web/src/services/gql/provider/links/langLink.ts
(1 hunks)web/src/services/i18n/translations/en.yml
(0 hunks)web/src/services/i18n/translations/ja.yml
(0 hunks)web/src/services/state/gqlErrorHandling.ts
(1 hunks)web/src/services/state/index.ts
(1 hunks)
💤 Files with no reviewable changes (2)
- web/src/services/i18n/translations/ja.yml
- web/src/services/i18n/translations/en.yml
🔇 Additional comments (7)
web/src/services/gql/provider/index.tsx (1)
17-17
: LGTM! The langLink integration looks good.The langLink is appropriately positioned in the Apollo link chain, after authentication and before the upload link. This ensures that language headers are added to authenticated requests.
Also applies to: 94-94
web/src/services/state/gqlErrorHandling.ts (2)
4-9
: LGTM! Enhanced error type definition.The expanded
GQLError
type with additional fields (code
anddescription
) provides more comprehensive error information.
10-11
: Verify the migration from single error to error array.The transition to array-based error management looks good, but ensure all consumers of the old
useError
hook are updated to useuseErrors
.Also applies to: 14-15
✅ Verification successful
Migration to array-based error management is complete
All occurrences of the old
useError
hook have been properly migrated to the newuseErrors
hook. No remaining usages of the old hook were found in the codebase.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining usage of the old useError hook rg "useError" --type tsLength of output: 463
web/src/services/gql/provider/links/errorLink.ts (1)
18-26
: LGTM! Comprehensive GraphQL error mapping.The error mapping implementation effectively captures all relevant error information from GraphQL errors, including type, message, code, and description.
web/src/services/state/index.ts (1)
8-8
: LGTM! Clean export update.The removal of
useError
export and retention ofuseSetError
aligns with the new array-based error handling approach.web/src/beta/features/Notification/hooks.ts (2)
2-3
: LGTM! Import changes align with multi-error handling.The transition from
useError
touseErrors
correctly supports the new multi-error handling approach.
86-91
: LGTM! Dependencies are properly maintained.All dependencies used in the effect are correctly listed in the dependency array.
…th-visualizer into refactor/error_handling_fe
b110bd7
to
2ccaeed
Compare
Overview
write overview on this pr.
#1342
What I've done
What I haven't done
How I tested
2025-01-22.17.35.11.1.mov
Which point I want you to review particularly
Memo
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Refactor
Documentation
The release introduces more robust error tracking and improved internationalization support.